/*
 * tJU-SGA.h
 *
 *  Created on: 16-07-2012
 *      Author: mith
 */

#ifndef TJU_SGA_H_
#define TJU_SGA_H_

#define Sqrt sqrt
#define Power pow

/*
 *********************************************************
 ******************** Structures *************************
 *********************************************************
*/

struct parameters {
	double n;
	double J;
	double t;
	double tPrim;
	double U;
	double beta;

	unsigned int L;
};

struct variables {
	double chiAB;
	double chiS;
	double chiT;
	double DeltaS;
	double DeltaT;
	double mu;
	double mAF;
	double d;
 };

/*
 *********************************************************
 ***************** Small useful functions ****************
 *********************************************************
*/

inline void clear(parameters &p) {
	p.n = p.J = p.t = p.tPrim = p.U = p.beta = 0.; p.L = 0;
}

inline void clear(variables &v) {
	v.chiAB = v.chiS = v.chiT = v.DeltaS = v.DeltaT = v.mu = v.mAF = v.d = 0;
}

inline void addTo(const variables &q, variables &v, double d=1.) {
	v.chiAB += q.chiAB*d;
	v.chiS += q.chiS*d;
	v.chiT += q.chiT*d;
	v.DeltaS += q.DeltaS*d;
	v.DeltaT += q.DeltaT*d;
	v.mu += q.mu*d;
	v.mAF += q.mAF*d;
	v.d += q.d*d;
}

inline void copyTo(variables &v, const variables &q, double d=1.) {
	v.chiAB = q.chiAB*d;
	v.chiS = q.chiS*d;
	v.chiT = q.chiT*d;
	v.DeltaS = q.DeltaS*d;
	v.DeltaT = q.DeltaT*d;
	v.mu = q.mu*d;
	v.mAF = q.mAF*d;
	v.d = q.d*d;
}

inline void copyTo(parameters &v, const parameters &q) {
	v.n = q.n;
	v.J = q.J;
	v.t = q.t;
	v.tPrim = q.tPrim;
	v.U = q.U;
	v.beta = q.beta;
	v.L = q.L;
}

inline double abs(double a) {
	if(a<0) a=-a;
	return a;
}

#endif /* TJU_SGA_H_ */
